/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dressingsocial.controller;

import com.dressingsocial.model.Dressing;
import com.dressingsocial.service.DressingService;
import java.util.List;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 *
 * @author hayate
 */

@Controller
public class HomeController {
    
    @Autowired
    private DressingService dressingService;
    
    @RequestMapping(value = {"/","/home","/index",""}, method = RequestMethod.GET)
    public String index(Model model) {
        Subject subject = SecurityUtils.getSubject();
        if(subject.isRemembered() || subject.isAuthenticated()) {
            return "redirect:/me/page";
        }
        List<Dressing> dressings = dressingService.findLatestDressings();
        model.addAttribute("dressings", dressings);
        return "index";
    }
    
}
